package com.common.basic.util;

import javax.servlet.http.HttpServletRequest;

public abstract class StringUtils {
	
	public static int toInteger(String text, int defvalue) 
	{
		int result = defvalue;
		if(text!=null)
		{
			try
			{
				result = Integer.parseInt(text);
			}catch(Exception ex){
				result = defvalue;
			}
		}
		return result;
	}
	
    public String serviceUrl(final HttpServletRequest request,
            final String page) {
        final StringBuilder sb = new StringBuilder();

        sb.append(request.getScheme());
        sb.append("://");
        sb.append(request.getServerName());

        final int port = request.getServerPort();

        if (port != 80) {
            sb.append(":");
            sb.append(port);
        }

        sb.append("/");
        sb.append(request.getContextPath());

        sb.append("/");
        sb.append(page);

        return (sb.toString());
    }


}
